#ifndef INFINITY_GRAPHICS_SIMPLE_MESH_H
#	define INFINITY_GRAPHICS_SIMPLE_MESH_H

#include "graphicsmesh.h"

namespace infinity {
	namespace graphics {

class SimpleMesh
:	public Mesh
{
public : //! @name Construction & Destruction
	//! @{
	SimpleMesh(
		dw::graphics::BufferObject::updates updates, dw::graphics::IndexBuffer::indextypes indexType,
		dw::graphics::primitive::types primitivesType, dw::graphics::VertexFormat* vertexFormat)
	:	m_primitivesType(primitivesType)
	,	m_vertexFormat(vertexFormat)
	,	m_indexBuffer(NULL)
	,	m_vertexBuffer(NULL)
	{
		dw::graphics::Renderer& renderer = dw::graphics::GraphicsManager::getInstance().getRenderer();

		m_indexBuffer = renderer.createIndexBuffer(updates, indexType);
		m_vertexBuffer = renderer.createVertexBuffer(updates, m_vertexFormat);
	}

	~SimpleMesh()
	{
		dw::graphics::Renderer& renderer = dw::graphics::GraphicsManager::getInstance().getRenderer();

		renderer.releaseIndexBuffer(m_indexBuffer);
		renderer.releaseVertexBuffer(m_vertexBuffer);
	}
	//! @}

public : //! @name
	//! @{
	virtual dw::graphics::IndexBuffer& getIndexBuffer() { return *m_indexBuffer; }
	virtual dw::graphics::VertexBuffer& getVertexBuffer() { return *m_vertexBuffer; }
	virtual const dw::graphics::IndexBuffer& getIndexBuffer() const { return *m_indexBuffer; }
	virtual const dw::graphics::VertexBuffer& getVertexBuffer() const { return *m_vertexBuffer; }
	//! @}

public : //! @name Commands
	//! @{
	virtual void render() const
	{
		dw::graphics::Renderer& renderer = dw::graphics::GraphicsManager::getInstance().getRenderer();

		renderer.setIndexBuffer(m_indexBuffer);
		renderer.setVertexBuffer(m_vertexBuffer);
		renderer.drawIndexedPrimitive(m_primitivesType, 0, m_indexBuffer->getCount());
	}
	//! @}

private : //! @name Data
	//! @{
	dw::graphics::primitive::types m_primitivesType;
	dw::graphics::VertexFormat* m_vertexFormat;
	dw::graphics::IndexBuffer* m_indexBuffer;
	dw::graphics::VertexBuffer* m_vertexBuffer;
	//! @}
};

	} // namespace graphics
} // namespace infinity

#endif // !INFINITY_GRAPHICS_SIMPLE_MESH_H
